﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Design;
using System.Windows.Forms.Design;
using System.Reflection;
using TFDP.Common.Services;

namespace TFDP.SimpleProcessor
{
    public class TemplateMappingsEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (value == null || value.GetType() != typeof(TemplateMappings))
            {
                return value;
            }

            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if (edSvc != null)
            {
                TemplateMappings clone = (TemplateMappings)((ICloneable)value).Clone();

                TemplateMappingsEditorWindow window = new TemplateMappingsEditorWindow(clone);

                edSvc.ShowDialog(window);

                return clone;
            }
            else
            {
                return value;
            }
        }
    }
}
